#ifndef OPERATE_PARM_H
#define OPERATE_PARM_H

#define SLAVE_NUM (32)
// #define SLAVE_NUM_CURRENT (28)
#pragma pack(1)

struct power_output_adaptor_paramter
{
  unsigned short level1_mo1;
  unsigned short level1_mo2;
  unsigned short level1_fa1;
  unsigned short level1_fa2;

  unsigned short level2_mo1;
  unsigned short level2_mo2;
  unsigned short level2_fa1;
  unsigned short level2_fa2;

  unsigned short strong_mo1;
  unsigned short strong_mo2;
  unsigned short strong_fa1;
  unsigned short strong_fa2;

  unsigned short mo1_up_limit;
  unsigned short mo2_up_limit;
  unsigned short fa_up_limit;
};

struct master_feature_bit
{
  unsigned char commander_comm : 1;
  unsigned char brake : 1;
  unsigned char rsvd : 6;
};

union master_feature_all
{
  struct master_feature_bit bit;
  unsigned char all;
};

struct master_conctrller_adaptor_paramter
{
  unsigned int mount_config;
  union master_feature_all check_feature;
  unsigned int sn_check;
};

struct check_feature_1_part
{
  unsigned char brake : 1;
  unsigned char power_comm : 1;
  unsigned char t1 : 1;
  unsigned char t2 : 1;
  unsigned char t3 : 1;
  unsigned char t4 : 1;
  unsigned char pd1 : 1;
  unsigned char pd2 : 1;
};

union check_feature_1_all
{
  volatile unsigned char all;
  struct check_feature_1_part part;
};

struct check_feature_2_part
{
  unsigned char pd3 : 1;
  unsigned char pd4 : 1;
  unsigned char envi_temperature : 1;
  unsigned char envi_humidity : 1;
  unsigned char mo : 1;
  unsigned char fa : 1;
  unsigned char seq : 1;
  unsigned char master_comm : 1;
};

union check_feature_2_all
{
  volatile unsigned char all;
  struct check_feature_2_part part;
};

struct laser_adaptor_paramter
{
  unsigned short level1_mo1;
  unsigned short level1_mo2;
  unsigned short level1_fa1;
  unsigned short level1_fa2;

  unsigned short level2_mo1;
  unsigned short level2_mo2;
  unsigned short level2_fa1;
  unsigned short level2_fa2;

  unsigned short strong_mo1;
  unsigned short strong_mo2;
  unsigned short strong_fa1;
  unsigned short strong_fa2;

  unsigned short mo1_up_limit;
  unsigned short mo2_up_limit;
  unsigned short fa_up_limit;

  unsigned char can_address;
  union check_feature_1_all check_feature_1;
  union check_feature_2_all check_feature_2;

  unsigned char pd1_low_limit;
  unsigned char pd2_low_limit;
  unsigned char pd3_low_limit;
  unsigned char pd4_low_limit;

    short t1_up_limit;
    short t1_low_limit;
    short t2_up_limit;
    short t2_low_limit;
    short t3_up_limit;
    short t3_low_limit;
    short t4_up_limit;
    short t4_low_limit;

  short envi_temperature_up_limit;
  short envi_temperature_low_limit;
  unsigned char envi_humidity_up_limit;
  unsigned int wave_length;
  unsigned char expansion_module_id;
  unsigned int sn;
};

struct adaptor_paramter_summary
{
  struct master_conctrller_adaptor_paramter master_conctrller_ada_parm;
  struct laser_adaptor_paramter laser_ada_parm[SLAVE_NUM];
};

struct power_module_state_bit
{
  unsigned char output_low_volt : 1;
  unsigned char brake : 1;
  unsigned char over_temperature_err : 1;
  unsigned char output_low_current : 1;
  unsigned char output_over_current : 1;
  unsigned char output_over_volt : 1;
  unsigned char input_err : 1;
  unsigned char output : 1;
};

union power_module_state_all
{
  unsigned char all;
  struct power_module_state_bit bit;
};

struct power_operating_paramter
{
  unsigned char power_state;
  short current1;
  unsigned char volt1;
  union power_module_state_all module1_state;

  short current2;
  unsigned char volt2;
  union power_module_state_all module2_state;

  short current3;
  unsigned char volt3;
  union power_module_state_all module3_state;

  short current4;
  unsigned char volt4;
  union power_module_state_all module4_state;
};

struct fault_code1_bit
{
  unsigned char pd1_err : 1;
  unsigned char pd2_err : 1;
  unsigned char pd3_err : 1;
  unsigned char pd4_err : 1;
  unsigned char t1_err : 1;
  unsigned char t2_err : 1;
  unsigned char t3_err : 1;
  unsigned char t4_err : 1;
};

union fault_code1_all
{
  volatile unsigned char all;
  struct fault_code1_bit bit;
};

struct fault_code2_bit
{
  unsigned char brake : 1;
  unsigned char seed_source_err : 1;
  unsigned char humidity_err : 1;
  unsigned char envi_err : 1;
  unsigned char seq_err : 1;
  unsigned char laser_comm_err : 1;
  unsigned char power_comm_err : 1;
  unsigned char master_comm_err : 1;
};

union fault_code2_all
{
  volatile unsigned char all;
  struct fault_code2_bit bit;
};

struct fault_code3_bit
{
  unsigned char expansion_module_err : 1;
  unsigned char rsvd:7;
};

union fault_code3_all
{
  volatile unsigned char all;
  struct fault_code3_bit bit;
};

struct running_state_bit
{
  unsigned char debug_mode : 1;
  unsigned char withdraw : 1;
  unsigned char standby_mode : 1;
  unsigned char rsvd : 5;
};

union running_state_all
{
  unsigned char all;
  struct running_state_bit bit;
};

struct seed_source_working_state
{
  unsigned char echo_state;
  unsigned char mod_module_state;
  unsigned char mt_temperature_state;
  unsigned char ast_state;
};

struct laser_operating_paramter
{
  unsigned char laser_op_state;
  unsigned int wave_length;
  unsigned short current1;
  union power_module_state_all module1_state;

  unsigned short current2;
  union power_module_state_all module2_state;

  unsigned short current3;
  union power_module_state_all module3_state;

  unsigned short current4;
  union power_module_state_all module4_state;

  unsigned char pd1;
  unsigned char pd2;
  unsigned char pd3;
  unsigned char pd4;
  short t1;
  short t2;
  short t3;
  short t4;
  unsigned char humidity;
  unsigned char intensity;
  short temperature;

  union running_state_all running_state;
  unsigned char seed_source_state;
  unsigned char expansion_module_state;

  union fault_code1_all fault_code1;
  union fault_code2_all fault_code2;
  union fault_code3_all fault_code3;
  unsigned char expansion_module_id;
  unsigned char rvsd[2];
};

struct master_err_code_bit
{
  unsigned char commander_comm_err : 1;
  unsigned char brake : 1;
  unsigned char rsvd : 6;
};

union master_err_code_all
{
  unsigned char all;
  struct master_err_code_bit bit;
};

struct master_operate_paramter
{
  unsigned char master_conctrller_state;
  union master_err_code_all master_err_code;
};

struct operating_paramter_summary
{
  struct master_operate_paramter master_operate_parm;
  struct laser_operating_paramter laser_operate_parm[SLAVE_NUM];
};

struct flash_adaptor_parameter
{
  unsigned char bcp_data;
  struct adaptor_paramter_summary flash_master_ada_parm;
};

#pragma pack()

extern struct pump_operating_paramter pump_operate_parm[4];
extern struct operating_paramter_summary operate_parm;
void operate_data_update(void);

#endif // OPERATE_PARM_H
